<?php
/**
 * peck 初始化  小鸡啄米
 *
 * @filesource pView.class.php
 * @package peck
 * @subpackage 
 * @version $id: 0.1, utf8, Sat Jan  9 11:17:11 CST 2010
 * @author LD King <kldscs[at]gmail.com>
 * @copyright Copyleft (D.) 2007 - 2010 MiFunny China Inc.
 * @link http://mifunny.info/
 * @see 
 */

defined('DS') or define('DS', DIRECTORY_SEPARATOR);
define('PCONFIG_FILE', dirname(__FILE__).DS.'peck-config.array.php');

class peck{
	public function __construct(){
		$hello = 1;
	}
	
}//ENF peck

//存储核心变量的一个对象
class _core{
	//核心对象数组
	private $_core = array(
		'version' => 0.1, //当前版本
		);
	private static $instance;
	
	//禁用一系列魔法函数
	private function __construct(){}
	private function __clone(){}
	//private function __get(){}
	//private function __set(){}
	private function __call($a,$b){
		throw new LogicException('('.__METHOD__.')'.'Error: no medhod found!');
	}
	
	/**
	 * 获得实例对象
	 * 
	 * @return self
	 */
	public static function object(){
		if( !(self::$instance instanceof self) ){
           self::$instance = new self();
           if( file_exists(PCONFIG_FILE) ){
           		self::$instance->_core = array_merge(self::$instance->_core, include(PCONFIG_FILE));
       		}else{
       			throw new LogicException('('.__METHOD__.')'.'Error: not found peck configure file!');
       		}
		}
       	return self::$instance;
	}
	
	/**
	 * 获得配置值
	 * 
	 * @param string $key 例: 'database/username'
	 *
	 * @return mixed
	 */
	public static function get($key){
		$keys = explode('/', $key);
		$core =& self::object()->_core;
		if( !empty($keys) ){ //不为空则返回具体值
			foreach($keys as $k){
				$core =& $core[$k];
			}
		}
		return $core;
	}
	
	/**
	 * 设置内部配置值
	 * 
	 * @param string $key 同get()
	 * @param mixed $value
	 */
	public static function set($key, $value){
		$keys = explode('/', $key);
		$core =& self::object()->_core;
		foreach($keys as $k){
			$core =& $core[$k];
		}
		$core = $value;
	}
	
}//END P
?>